/*
 * @Author: humengchuan 531537052@qq.com
 * @Date: 2025-02-25 14:21:00
 * @LastEditors: humengchuan 531537052@qq.com
 * @LastEditTime: 2025-02-25 14:22:50
 * @FilePath: \project-my\forum-project\middlewares\login.middleware.js
 * @Description: 中间件
 */
const verifyLogin = async (req, res, next) => {
  const { username, password } = req.body
  if (!username || !password) {
    return res.status(400).json({
      message: '用户名或密码不能为空'
    })
  }
  await next()
}

const verifyToken = async (req, res, next) => {
  const token = req.headers.authorization
  if (!token) {
    return res.status(401).json({
      message: 'Unauthorized'
    })
  }
  const decoded = jwt.verify(token, 'secret')
  req.user = decoded
  await next()
}

modules.exports = { verifyLogin, verifyToken }